package common;

import common.JobObject;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Request")
public class JobsPackage {
	private ArrayList<JobObject> jobs = new ArrayList<JobObject>();
	private Long deadline;
	private Long time;
	private int budget;
	private int cost;
	private String from;
	private String type;
	private String optimizeType;
	private Long timestamp;
    private String clientID = null;
    private int NumberOfJobs = 0;
    private int NumberOfJobsRunning = 0;
    private int NumberOfJobsWaiting = 0;
    private int NumberOfJobsCompleted = 0;
    private int NumberOfJobsFailed = 0;
    private int TotalCost = 0;
    private long startTime, endTime;
    private boolean jpCompletedIndcator = false;
	
	@XmlAttribute
	public String getFrom() {
		return from;
	}
	public void setFrom(String from) {
		this.from = from;
	}
	@XmlAttribute
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Long getTimestamp() {
		return timestamp;
	}
	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}
	public void addJob(JobObject jobObject) {
		jobs.add(jobObject);
	}

    public void removeJob(JobObject jobObject) {
		jobs.remove(jobObject);
	}

	public void setDeadline(Long deadline) {
		this.deadline = deadline;
	}

	public Long getDeadline() {
		return deadline;
	}

	public void setBudget(int budget) {
		this.budget = budget;
	}

	public int getBudget() {
		return budget;
	}
	
	public void setTime(Long time) {
		this.time = time;
	}

	public Long getTime() {
		return time;
	}
	
	public void setCost(int cost) {
		this.cost = cost;
	}

	public int getCost() {
		return cost;
	}
	
	public ArrayList<JobObject> getJobs() {
		return jobs;
	}
	
	public void setJobs(ArrayList<JobObject> jobs) {
		this.jobs = jobs;
	}

    public void setClientID(String aClientID){
        this.clientID = aClientID;
    }

    public String getClientID(){
        return clientID;
    }

    public int getNumberOfJobs(){
        NumberOfJobs = jobs.size();
        return NumberOfJobs;
    }

    public void addNumberOfJobsRunning(){
        this.NumberOfJobsRunning ++;
    }

    public void deleteNumberOfJobsRunning(){
        this.NumberOfJobsRunning --;
    }

    public void addNumberOfJobsCompleted(){
        this.NumberOfJobsCompleted ++;
    }

    public void deleteNumberOfJobsCompleted(){
        this.NumberOfJobsCompleted --;
    }

    public void addNumberOfJobsWaiting(){
        this.NumberOfJobsWaiting ++;
    }

    public void deleteNumberOfJobsWaiting(){
        this.NumberOfJobsWaiting --;
    }
    public void addNumberOfJobsFailed(){
        this.NumberOfJobsFailed ++;
    }

    public void deleteNumberOfJobsFailed(){
        this.NumberOfJobsFailed --;
    }

    public int getNumberOfJobsRunning(){
         int count = 0;
        for(int i=0;i<jobs.size();i++){
          if(jobs.get(i).getStatus().equals("RUNNING"))count++;
        }
         NumberOfJobsRunning = count;
         return NumberOfJobsRunning;
    }

    public int getNumberOfJobsCompleted(){
         int count = 0;
        for(int i=0;i<jobs.size();i++){
          if(jobs.get(i).getStatus().equals("COMPLETED"))count++;
        }
         NumberOfJobsCompleted = count;
         return NumberOfJobsCompleted;
    }
    
    public int getNumberOfJobsFailed(){
        int count = 0;
       for(int i=0;i<jobs.size();i++){
         if(jobs.get(i).getStatus().equals("FAILED"))count++;
       }
        NumberOfJobsFailed = count;
        return NumberOfJobsFailed;
   }

    public int getNumberOfJobsWaiting(){
        int count = 0;
        for(int i=0;i<jobs.size();i++){
          if(jobs.get(i).getStatus().equals("WAITING"))count++;
        }
         NumberOfJobsWaiting = count;
        return NumberOfJobsWaiting;
    }
    
    public int getTotalCost(){
       int acc = 0;
       for(int i=0;i<jobs.size();i++){
    	   
    	   if (jobs.get(i).getStatus().matches("COMPLETED") || jobs.get(i).getStatus().matches("COMPLETED"))
    		   acc += (int) ((jobs.get(i).getJobEndTime() - jobs.get(i).getJobStartTime())/1000 
    	   				* jobs.get(i).getWorkerCost());
    	    
       }
        TotalCost = acc;
        return TotalCost;
   }
    
	public boolean isJpCompletedIndcator() {
		return jpCompletedIndcator;
	}
	public void setJpCompletedIndcator(boolean jpCompletedIndcator) {
		this.jpCompletedIndcator = jpCompletedIndcator;
	}
	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}
	public long getStartTime() {
		return startTime;
	}
	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}
	public long getEndTime() {
		return endTime;
	}
	public void setOptimizeType(String optimizeType) {
		this.optimizeType = optimizeType;
	}
	public String getOptimizeType() {
		return optimizeType;
	}

	
}
